<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Models_Droplists extends Page
{
       public $imgBack = null;
       public $Label4 = null;
       public $hiddenModel = null;
       public $hiddenMnfr = null;
       public $editModel = null;
       public $JTGridModel = null;
       public $JTGridMnfr = null;
       public $btnModelDelete = null;
       public $btnModelUpdate = null;
       public $btnModelAdd = null;
       public $btnMnfrDelete = null;
       public $btnMnfrUpdate = null;
       public $btnMnfrAdd = null;
       public $Label1 = null;
       public $editMnfr = null;
       public $Value = null;
       public $JTSiteTheme1 = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/back2.png"
       <?php

       }

       function btnModelDeleteClick($sender, $params)
       {
        $mnfr_id = $this->hiddenMnfr->getValue();
        $model_id = $this->hiddenModel->getValue();
        mysql_query("DELETE FROM lookup_models_tbl WHERE id='".$model_id."'");

        redirect('veh_models_droplists.php?mnfr_id='.$mnfr_id);
       }

       function btnModelUpdateClick($sender, $params)
       {
        $mnfr_id = $this->hiddenMnfr->getValue();
        $model_id = $this->hiddenModel->getValue();
        mysql_query("UPDATE lookup_models_tbl SET model_name='".$this->editModel->getText()."'
        WHERE id='".$model_id."'") or
        die("UPDATE MODEL".mysql_error());

        redirect("veh_models_droplists.php?mnfr_id=".$mnfr_id."&model_id=".$model_id);
       }

       function btnModelAddClick($sender, $params)
       {
        $mnfr_id = $this->hiddenMnfr->getValue();
        mysql_query("INSERT INTO lookup_models_tbl (mnfr_id, model_name)
        VALUES ('".$mnfr_id."','".$this->editModel->getText()."')") or
        die("INSERT MODEL".mysql_error());

        redirect('veh_models_droplists.php?mnfr_id='.$mnfr_id);
       }

       function JTGridModelShow($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       $model_id = $this->hiddenModel->getValue();
       $arr_model = array();
       $result_model = mysql_query("SELECT * FROM lookup_models_tbl WHERE mnfr_id='".$mnfr_id."'") or die("SELECT MODEL".mysql_error());
       while($row_model = mysql_fetch_array($result_model))
       {
         $model_id = $row_model['id'];
         $model_value = $row_model['model_name'];
         $model_link = "<a href=veh_models_droplists.php?mnfr_id=".$mnfr_id."&model_id=".$model_id.">".$model_value.
         "</a>";
         $arr_model[] = array('Model' => $model_link);
       }
         $this->JTGridModel->setCellData($arr_model);
       }

       function Vehicle_Models_DroplistsCreate($sender, $params)
       {
       $this->hiddenMnfr->setValue($_GET['mnfr_id']);
       $this->hiddenModel->setValue($_GET['model_id']);
       $mnfr_id = $this->hiddenMnfr->getValue();
       $model_id = $this->hiddenModel->getValue();

       $this->imgBack->setLink('vehicle_list.php?company_id='.$_SESSION['company_id']);

       $result_mnfr = mysql_query("SELECT * FROM lookup_vehicle_tbl WHERE id='".$mnfr_id."'") or
       die("SELECT MNFR".mysql_error());
       $row_mnfr = mysql_fetch_array($result_mnfr);

       $result_model = mysql_query("SELECT * FROM lookup_models_tbl WHERE id='".$model_id."'") or
       die("SELECT MODEL".mysql_error());
       $row_model = mysql_fetch_array($result_model);

       $this->editMnfr->setText($row_mnfr['value']);
       $this->editModel->setText($row_model['model_name']);
       }

       function btnMnfrDeleteClick($sender, $params)
       {
        $mnfr_id = $this->hiddenMnfr->getValue();
        mysql_query("DELETE FROM lookup_vehicle_tbl WHERE id='".$mnfr_id."'");

        redirect('veh_models_droplists.php');
       }

       function btnMnfrUpdateClick($sender, $params)
       {
        $mnfr_id = $this->hiddenMnfr->getValue();
        mysql_query("UPDATE lookup_vehicle_tbl SET value='".$this->editMnfr->getText()."'
        WHERE id='".$mnfr_id."'");

        redirect('veh_models_droplists.php?mnfr_id='.$mnfr_id);
       }

       function btnMnfrAddClick($sender, $params)
       {
       mysql_query("INSERT INTO lookup_vehicle_tbl
       (category, value) VALUES ('manufacturer','".$this->editMnfr->getText()."')") or
       die("INSERT MNFR".mysql_error());

       redirect('veh_models_droplists.php');
       }

       function JTGridMnfrShow($sender, $params)
       {
       $arr_mnfr = array();
       $result_mnfr = mysql_query("SELECT * FROM lookup_vehicle_tbl WHERE category='manufacturer'") or die("SELECT MNFR".mysql_error());
       while($row_mnfr = mysql_fetch_array($result_mnfr))
       {
         $mnfr_id = $row_mnfr['id'];
         $mnfr_value = $row_mnfr['value'];
         $mnfr_link = "<a href=veh_models_droplists.php?mnfr_id=".$mnfr_id.">".$mnfr_value.
         "</a>";
         $arr_mnfr[] = array('Manufacturer' => $mnfr_link);
       }
         $this->JTGridMnfr->setCellData($arr_mnfr);
       }







}

global $application;

global $Vehicle_Models_Droplists;

//Creates the form
$Vehicle_Models_Droplists=new Vehicle_Models_Droplists($application);

//Read from resource file
$Vehicle_Models_Droplists->loadResource(__FILE__);

//Shows the form
$Vehicle_Models_Droplists->show();

?>